package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo3 {
    public static void main(String[] args) {
        try (
                Connection connection = DBUtil.getConnection();
        ) {
            Statement statement = connection.createStatement();
            String sql = "SELECT id,name,salary,age " +
                    "FROM teacher";

            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
                int id = rs.getInt("id");
                //获取name字段的值 teacher表中name是VARCHAR类型(字符串)
                String name = rs.getString("name");
                int salary = rs.getInt("salary");
                int age = rs.getInt("age");
                System.out.println(id + "," + name + "," + salary + "," + age);
            }



        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
